package org.example.ssh

import net.schmizz.sshj.SSHClient
import org.example.ssh.base.SSH
import org.example.ssh.base.SshCtx
import org.example.ssh.base.executeCmdPrint
import org.example.ssh.base.uploadDirectoryRecursive

suspend fun main() {
    val list = SSH.getGroup("dev_ztest01-HK-5001")
    SSH.execF(list) {
        DeployApp().deploy(it)
    }
}

class DeployApp {

    suspend fun deploy(sshCtx: SshCtx) {
        val sftp = sshCtx.cli.newSFTPClient()
//        uploadDirectoryRecursive(sftp, "./配置/app/ztest01", "/home")

//        sftp.put("./build/libs/ZTest01-1.0.jar", "/home/ztest01/ZTest01-1.0.jar")

//        executeCmdPrint(sshCtx.cli, "cd /home/ztest01 && ls -la")

//        executeCmdPrint(sshCtx.cli, "cd /home/ztest01 && docker-compose -f build-compose.yml build")
//        executeCmdPrint(sshCtx.cli, "cd /home/ztest01 && docker-compose -f run-compose.yml down")
//        executeCmdPrint(sshCtx.cli, "cd /home/ztest01 && docker-compose -f run-compose.yml up -d")

//        executeCmdPrint(sshCtx.cli, "docker ps")
        executeCmdPrint(sshCtx.cli, "cd /home/ztest01 && docker-compose -f run-compose.yml logs ztest01 ")

    }

}










